package com.blueseaapps;

import java.util.UUID;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.blueseaapps.c2dm.C2DMessaging;
import com.blueseaapps.utility.RegistrationTokenManager;
import com.blueseaapps.utility.UserDataManager;

public class StartActivity extends Activity {
	/** Called when the activity is first created. */
	private Button btn_begin;
	private TextView tvUpdateAvailable;

	private Button btnAbout;

	private final String LOG_TAG=getClass().getSimpleName();
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.start);


		btn_begin = (Button)findViewById(R.id.button_begin);
		btn_begin.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent beginIntent = new Intent(v.getContext(),CategorySelectActivity.class);
				startActivity(beginIntent);
			}
		});

		btnAbout = (Button)findViewById(R.id.button_about);
		btnAbout.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent beginIntent = new Intent(v.getContext(),AboutPageActivity.class);
				startActivity(beginIntent);				
			}
		});


	}

	@Override
	protected void onResume() {
		super.onResume();
		String storedRegId = UserDataManager.getRegistrationId(getApplicationContext());
		if(storedRegId == null){
			registerForNotification();
		}
		String updateAvailable = getIntent().getStringExtra("com.blueseaapps.photoquiz.UPDATE_AVAILABLE");
		if(updateAvailable != null){
			tvUpdateAvailable = (TextView) findViewById(R.id.tv_update_avlbl);
			tvUpdateAvailable.setText(updateAvailable);
		}
	}

	private void registerForNotification() {
		Log.d("StartActivity", "Start registration for notification");
		C2DMessaging.register(getApplicationContext(), "blueseaapps@gmail.com");
	}

}